package org.example.lambda;

import java.util.function.BiConsumer;

/**
 * @author why
 * @date 2022/11/1318:11
 */
public class ExceptionHandleLambdaToLearnWrapperLambda {


    public static void main(String[] args) {

        int[] someNumbers = new int[]{1,2,3,4};

        int key = 0;

        process(someNumbers,key, wrapperLambda((k,v)-> System.out.println(k/v)));

    }

    private static BiConsumer<Integer,Integer> wrapperLambda(BiConsumer<Integer,Integer> consumer) {
        return (k,v)->{
            try {
                consumer.accept(k,v);
            }catch (ArithmeticException arithmeticException){
                System.out.println("wrapperLambda exception");
            }
        };
    }

    private static void process(int[] someNumbers, int key, BiConsumer<Integer,Integer> consumer) {
        for (int n : someNumbers){
            try {
                consumer.accept(n, key);
            }catch (ArithmeticException arithmeticException){
                System.out.println("an exception hapend");
            }
        }
    }


}
